﻿Public Class frmNewEmployee
    Friend upd = 0
    Private Sub btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsave.Click
        If txtname.Text.Trim = "" Then
            myMsgbox.show("Please input Employee Name!", "Employee")
            txtname.Focus()
            txtname.SelectAll()
            Exit Sub
        End If
        If cbosex.Text = "" Then
            myMsgbox.show("Please Select Employee Sex!", "Employee")
            cbosex.Focus()
            Exit Sub
        End If
        If txtphone.Text.Trim = "" Then
            myMsgbox.show("Please input Employee Phone!", "Employee")
            txtphone.Focus()
            txtphone.SelectAll()
            Exit Sub
        End If
        If Validator.IsPhone(txtphone.Text) = False Then
            myMsgbox.show("Please input Valid Phone number! Ex:087 397 317 or 012 357 3256", "Employee")
            txtphone.Focus()
            txtphone.SelectAll()
            Exit Sub
        End If
        If txtadr.Text.Trim = "" Then
            myMsgbox.show("Please input employee address!", "Employee")
            txtadr.Focus()
            txtadr.SelectAll()
            Exit Sub
        End If
        Exit Sub
        If upd = 0 Then
            ClassEmployee.addEmployee(txtname.Text, cbosex.Text, txtphone.Text, txtadr.Text, dtpdob.Value, txtpob.Text, dtpjoin.Value, PictureBox1.Image)
        Else
            MessageBox.Show("Update")
        End If

        Me.DialogResult = Windows.Forms.DialogResult.OK
        Me.Close()
    End Sub

    Private Sub frmNewEmployee_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        loadGroup()
    End Sub

    Private Sub loadGroup()
        Dim dt As New DataTable
        dt = Cmd.ExecuteDataTable("select group_id,group_name from tbl_group where active=1")
        cbousergroup.DisplayMember = "group_name"
        cbousergroup.ValueMember = "group_id"
        cbousergroup.DataSource = dt
    End Sub

    Private Sub btnbrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnbrowse.Click
        Dim ofd As New OpenFileDialog
        ofd.Filter = "jpeg|*.jpg|bmp|*.bmp|all files|*.*"
        If ofd.ShowDialog = Windows.Forms.DialogResult.OK Then
            Me.PictureBox1.Image = System.Drawing.Image.FromFile(ofd.FileName)
        End If
    End Sub
End Class